#include "fibonacciHeap.h"
#include "graph.h"
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
#include <ctime>

vector<int> dijkstra(Graph graph, int s, int t)
{
	RootList q;
	Vertex v(0,0), u(0,0);
	AdjacencyList *n;
	AdjacencyList::iterator it;
	vector<int> dist(graph.getNumberOfNodes() + 1);
	vector<bool> visited(graph.getNumberOfNodes() + 1);
	int i;
	for(i = 1; i < (int)dist.size(); i++){
		if(i != s){
			dist[i] = -1;
		} else dist[i] = 0;
	}
	for(i = 1; i < (int)visited.size(); i++){
		visited[i] = false;
	}
	q.incertV(Vertex(s, 0));
	while(!q.isEmpty())
	{
		v = q.deleteminV();
		if(v.getName() == t) break;
		visited[v.getName()] = true;
		n = graph.getNeighbourhood(v.getName());
		for(it = n->begin(); it != n->end(); it++){
			u.setName((*it).getName());
			u.setDist((*it).getDist());	
			if(!visited[u.getName()]){
				if(dist[u.getName()] == -1){
					dist[u.getName()] = dist[v.getName()] + u.getDist();
					q.incertV(Vertex(u.getName(), dist[u.getName()]));
				}
				else {
					int aux = dist[u.getName()];
					dist[u.getName()] =
							(dist[v.getName()] + u.getDist()) > dist[u.getName()]
							? dist[u.getName()] : (dist[v.getName()] + u.getDist());

					q.decreasekeyV(Vertex(u.getName(), aux), dist[u.getName()]);
				}
			}
		}
	}
	return dist;
}


#define SIZE 200


int main(int argc, char *argv[])
{
	assert(argc == 3);
	Graph graph;
	//RootList h;
	graph.loadGraph();
	/*int j = SIZE;
	for(int i = 0; i < SIZE; i++)
	{
		j--;
		h.incert(FibonacciHeap(i,j));	

	}
	j = SIZE;
	//h.printPos();
        for(int i = 0; i < SIZE; i++)
        {
		j--;
                h.decreasekey(FibonacciHeap(i,j),j*-1);
        }
	for(int i = 0; i < SIZE; i++){
		h.deletemin();
		h.printHeap();
	}*/
	
	vector<int> dist;
	dist = dijkstra(graph, atoi(argv[1]),atoi(argv[2]));
        int distance = dist[atoi(argv[2])];
	if(distance != -1) {
		cout << dist[atoi(argv[2])] << endl;
	} else
		cout << "inf" << endl;

	return 0;
}

